<template>
    <Card style="height:900px">
        <Row>
            <Col span="24">
            <Card style="height:80px">
                <Button type="primary" @click="back" style="float:right;margin-right:13px">返回</Button>
            </Card>
            <Card>
                <Row type="flex" justify="center" align="middle" class="list-query">
                    <Table border :columns="columns" :data="columnData" style="width: 100%;"></Table>
                </Row>
                <div class="bottom-page-div">
                    <Page :total="adjustResult.total" :current="adjustResult.pageNum" :page-size="adjustResult.pageSize" size="small" show-elevator show-sizer show-total @on-change="pageChange" @on-page-size-change="sizeChange"></Page>
                </div>
            </Card>
            </Col>
        </Row>
    </Card>
</template>

<script>
export default {
  name: 'mutative-router',
  data () {
    return {
      adjustResult: {
        pageNum: 1,
        pageSize: 10,
        total: 0
      },
      paymentCondition: {
        custName: '',
        custIdNumber: '',
        loanId: '',
        repaymentBeginDate: '',
        repaymentEndDate: '',
        repaymentStatus: '',
        audistStatus: '',
        payType: '',
        pageNum: 1,
        pageSize: 10,
        total: 0
      },
      columns: [
        {
          type: 'index',
          title: '序号',
          width: 60
        },
        {
          title: '客户姓名',
          key: 'custName',
          align: 'center'
        },
        {
          title: '身份证',
          key: 'custCardNo',
          align: 'center'
        },
        {
          title: '还款期数',
          key: 'currTenor',
          align: 'center'
        },
        {
          title: '资金方',
          key: 'fundName',
          align: 'center'
        },
        {
          title: '总欠款金额',
          key: 'amount',
          align: 'center'
        },
        {
          title: '实还金额',
          key: 'amountAct',
          align: 'center'
        },
        {
          title: '还款方式',
          key: 'repaymentWays',
          align: 'center',
          render: (h, params) => {
            if (params.row.repaymentWays === '1') { // 对公转账
              return h('span', {
                props: {
                  type: 'text',
                  size: 'small'
                }
              }, '对公转账')
            }
            if (params.row.repaymentWays === '2') { // 支付宝转账
              return h('span', {
                props: {
                  type: 'text',
                  size: 'small'
                }
              }, '对公转账')
            }
          }
        },
        {
          title: '状态',
          key: 'contractStatus',
          align: 'center',
          // 0正常 1逾期 2结清 3提前结清 10核销
          render: (h, params) => {
            if (params.row.contractStatus === '0') { // 对公转账
              return h('span', {
                props: {
                  type: 'text',
                  size: 'small'
                }
              }, '正常')
            }
            if (params.row.contractStatus === '1') { // 支付宝转账
              return h('span', {
                props: {
                  type: 'text',
                  size: 'small'
                }
              }, '逾期')
            }
            if (params.row.contractStatus === '2') { // 支付宝转账
              return h('span', {
                props: {
                  type: 'text',
                  size: 'small'
                }
              }, '结清')
            }
            if (params.row.contractStatus === '3') { // 支付宝转账
              return h('span', {
                props: {
                  type: 'text',
                  size: 'small'
                }
              }, '提前结清')
            }
            if (params.row.contractStatus === '10') { // 支付宝转账
              return h('span', {
                props: {
                  type: 'text',
                  size: 'small'
                }
              }, '核销')
            }
          }

        },
        {
          title: '备注',
          key: 'remarks',
          align: 'center'
        }
      ],
      columnData: []
    }
  },
  created () {
    // 初始化当前页面请求对象实例
    this.$ajax = this.$util.ajax()
    this.paymentCondition = this.$route.params.paymentCondition
    this.initData()
  },
  computed: {
    avatorImage () {
      return localStorage.avatorImgPath
    }
  },
  methods: {
    pageChange: function (pageNum) {
      var vm = this
      vm.adjustResult.pageNum = pageNum
      vm.initData()
    },
    sizeChange: function (pageLength) {
      var vm = this
      vm.adjustResult.pageSize = pageLength
      vm.initData()
    },
    initData () {
      var vm = this
      var payType = vm.paymentCondition.payType
      var audistStatus = vm.paymentCondition.audistStatus
      if (payType === '1') { // 代还款
        if (audistStatus === '1') { // 通过
          this.$ajax.post(this.$appContext.marvels_core_financial + 'financial/loan/replacePayment/service/replacePaymentAdoptList', this.adjustResult).then(re => {
            var data = re.data
            // console.info(re.data)
            vm.columnData = data.data.list
            vm.adjustResult.total = data.data.total
          }).catch(er => {

          })
        } else if (audistStatus === '2') { // 拒绝
          this.$ajax.post(this.$appContext.marvels_core_financial + 'financial/loan/replacePayment/service/replacePaymentRefuseList', this.adjustResult).then(re => {
            var data = re.data
            vm.columnData = data.data.list
            vm.adjustResult.total = data.data.total
          }).catch(er => {

          })
        }
      } else if (payType === '2') { // 提前结清
        if (audistStatus === '1') { // 通过
          this.$ajax.post(this.$appContext.marvels_core_financial + 'financial/loan/earlyPayment/service/earlyPaymentAdoptList', this.adjustResult).then(re => {
            var data = re.data
            vm.columnData = data.data.list
            vm.adjustResult.total = data.data.total
          }).catch(er => {

          })
        } else if (audistStatus === '2') { // 拒绝
          this.$ajax.post(this.$appContext.marvels_core_financial + 'financial/loan/earlyPayment/service/earlyPaymentRefuseList', this.adjustResult).then(re => {
            var data = re.data
            vm.columnData = data.data.list
            vm.adjustResult.total = data.data.total
          }).catch(er => {

          })
        }
      }
    },
    back () {
      var vm = this
      var paymentCondition = vm.paymentCondition
      // this.$router.push({name:'replace-payment-apply-data',params:{paymentCondition}});//类似post传参
      var payType = paymentCondition.payType
      if (payType === '2') { // 提前结清
        this.$router.push({ name: 'early-settle-apply', params: { paymentCondition } })// 类似post传参
      } else { // 代还款
        this.$router.push({ name: 'replace-payment-apply', params: { paymentCondition } })// 类似post传参
      }
    }

  }
}
</script>
<style>
.font-style {
  float: left;
  margin-left: -88px;
  text-align: center;
}
.popup-style {
  margin: 18px;
  width: 300px;
  margin-left: 27%;
  margin-top: 31px;
}
.bottom-page-div {
  margin-top: 120px;
  text-align: center;
}
</style>
